package com.heima.kafka.spring.producer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    @GetMapping("/hello")
    public String hello(){
        for (int i = 0; i <5 ; i++) {
            if(i%2==0){
                kafkaTemplate.send("topicA","hello itcast");
            }else{
                kafkaTemplate.send("topicA","hello kafka");
            }
        }

        return "success";
    }
}
